﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
using System.Net.Mail;
using System.Net.Mime;
using System.Collections;
using DotNetNuke.Entities.Users;
using System.Globalization;

namespace Triax.Modules.Department
{
    /// -----------------------------------------------------------------------------
    ///<summary>
    /// The Controller class for the Customer
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    public class CustomerController : ISearchable, IPortable
    {
        public PetaPoco.Database db;// = new PetaPoco.Database(ConfigurationManager.AppSettings["SiteSqlServer"], "System.Data.SqlClient");
        private static CustomerController _Instance;
        public static CustomerController Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new CustomerController();
                    _Instance.db = new PetaPoco.Database(ConfigurationManager.AppSettings["SiteSqlServer"], "System.Data.SqlClient");
                }

                return _Instance;
            }
        }
        public static DateTime convertNgay(string ngaybatdau)
        {
            try
            {
                string[] dtemp = ngaybatdau.Split('/');
                if (dtemp.Length > 2)
                {
                    return DateTime.ParseExact(ngaybatdau, "d/M/yyyy", CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                return DateTime.Parse("01/01/1900");
            }
            return DateTime.Parse("01/01/1900");
        }

        public static int convertInt(string text)
        {
            int res = 0;
            try
            {
                int.TryParse(text, out res);
            }
            catch
            {
                res = 0;
            }
            return res;
        }
        public static int? convertIntOrNull(string text)
        {
            int? res = null;
            try
            {
                res = Convert.ToInt32(text);
            }
            catch
            {
            }
            return res;
        }
        public static string showNgayTuoi(string ngay)
        {

            string res = "";
            DateTime ngaymuon = Convert.ToDateTime(ngay);
            DateTime ngaytra = DateTime.Now;
            TimeSpan Time = ngaymuon - ngaytra;
            int TongSoNgay = Time.Days;


            if (ngaymuon.Year <= 1900)
                res = "";
            else
                res = Math.Abs(TongSoNgay).ToString();
            return res;

        }
        public static float convertFloat(string text)
        {
            float res = 0;
            try
            {
                float.TryParse(text, out res);
            }
            catch
            {
                res = 0;
            }
            return res;
        }

        #region Constructors

        public CustomerController()
        {
        }

        #endregion

        #region Public Methods


        public bool sendMai2(string email, string title, int id, int nguoinhap)
        {
            //   sendMai("hieulc1977@yahoo.com;cuongchiluong@yahoo.com", "MIS: Thêm khách hàng ", "<b>Tên khách hàng:  " + objCustomer.TenKhachHang + "</b><br/> <b>Địa chỉ:  " + objCustomer.DiaChi + "</b><br/> Điện thoại: " + objCustomer.SoDienThoai + "<br/> Email: " + objCustomer.TempStr2 + "<br/> Nội dung yêu cầu:<br/> " + objCustomer.TempStr3 + "<br/> Cán bộ nhập: " + getNguoitao(this.UserId.ToString()) + "<br/> Cán bộ Pre-Sale: " + getNguoitao(objCustomer.TempInt1.ToString()));
            CustomerController objDepartments = new CustomerController();
            Customer objCustomer = new Customer();
            DotNetNuke.Entities.Users.UserController objUserController = new DotNetNuke.Entities.Users.UserController();
            ArrayList listroles = objUserController.GetUsers(0, true, true);
            List<UserInfo> liUserInfo = new System.Collections.Generic.List<UserInfo>();
            List<UserInfo> liUserInfo1, liUserInfo2, liUserInfo3, liUserInfo4, liUserInfo5, liUserInfo6 = new List<UserInfo>();
            UserInfo temp = new DotNetNuke.Entities.Users.UserInfo();


            temp.UserID = 0;
            temp.DisplayName = "---------------";
            liUserInfo1 = new List<UserInfo>();
            liUserInfo2 = new List<UserInfo>();
            liUserInfo3 = new List<UserInfo>();
            liUserInfo4 = new List<UserInfo>();
            liUserInfo5 = new List<UserInfo>();
            foreach (DotNetNuke.Entities.Users.UserInfo obj2 in liUserInfo)
            {
                if (obj2.IsInRole("Pre-Sale"))
                {
                    liUserInfo2.Add(obj2);
                }
            }

            objCustomer = objDepartments.GetCustomer(0, id);
            string noidung = "";
            noidung += "<b>Tên khách hàng:  </b>" + objCustomer.TenKhachHang;
            noidung += "<br/> <b>Địa chỉ: </b> " + objCustomer.DiaChi;
            noidung += "<br/> <b>Người liên hệ: </b>" + objCustomer.TempStr1;
            noidung += "<br/><b> Điện thoại:</b> " + objCustomer.SoDienThoai;
            noidung += "<br/> <b>Email: </b>" + objCustomer.TempStr2;

            noidung += "<br/> <b>Nội dung yêu cầu:</b><br/> " + objCustomer.TempStr3;
            noidung += "<br/> <b>Cán bộ nhập: </b> " + getNguoitao(nguoinhap.ToString());


            ContractTemplateLogController ctr = new ContractTemplateLogController();
            ContractTemplateLog obj = new ContractTemplateLog();
            DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserById(0, nguoinhap);
            //user.Email
            // danh sach cac ytu cau
            List<ContractTemplateLog> ds = ctr.GetContractTemplateLogsByCond(0, " AND ContractTemplateID = " + id, "");
            noidung += "<br/> <b>Kết quả: </b>";
            foreach (ContractTemplateLog obj2 in ds)
            {
                noidung += "<br/> Ngày: " + obj2.CreateDate.ToString("dd/MM/yyyy") + "  " + "" + obj2.GhiChu;
            }

            bool check = true;

            string[] mails = email.Split(';');
            string EmailName = "senwebthongbao@gmail.com";//ConfigurationSettings.AppSettings["EmailName"];
            string EmailPassword = "senwebthongbao123456";// ConfigurationSettings.AppSettings["EmailPassword"];
            string EmailHost = "smtp.gmail.com";// ConfigurationSettings.AppSettings["EmailHost"];
            string EmailPort = "587";// ConfigurationSettings.AppSettings["EmailPort"];
            string res = "";

            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new System.Net.NetworkCredential(EmailName, EmailPassword);
            SmtpServer.Port = int.Parse(EmailPort);
            SmtpServer.Host = EmailHost;
            SmtpServer.EnableSsl = true;
            MailMessage mail = new MailMessage();

            try
            {
                mail.From = new MailAddress(EmailName, "MIS Thông báo", System.Text.Encoding.UTF8);
                Byte i;

                //  mail.To.Add("nammct@gmail.com");
                if (user != null && user.Email.Length > 7)
                {
                    bool checkemail = true;

                    for (int ii = 0; ii < mails.Length; ii++)
                    {
                        if (mails[ii].Trim() == user.Email.Trim())
                        {
                            checkemail = false;
                        }
                    }
                    if (checkemail)
                        mail.To.Add(user.Email);
                }
                // gửi email tới các presale
                if (liUserInfo2 != null && liUserInfo2.Count > 0)
                {
                    foreach (DotNetNuke.Entities.Users.UserInfo obj3 in liUserInfo2)
                    {
                        bool checkemail = true;

                        for (int ii = 0; ii < mails.Length; ii++)
                        {
                            if (mails[ii].Trim() == obj3.Email.Trim())
                            {
                                checkemail = false;
                            }
                        }
                        if (checkemail)
                        {
                            if (obj3.Email.Length > 7)
                                mail.To.Add(obj3.Email);
                        }
                    }
                }
                for (int ii = 0; ii < mails.Length; ii++)
                {
                    mail.To.Add(mails[ii]);
                }
                mail.Subject = title + objCustomer.TenKhachHang;
                //LinkedResource logo = new LinkedResource(path);
                //logo.ContentId = "companylogo";
                // AlternateView alternateView1 = AlternateView.CreateAlternateViewFromString(noidung, null, MediaTypeNames.Text.Html);
                //   alternateView1.LinkedResources.Add(logo);
                //mail.AlternateViews.Add(alternateView1);

                mail.IsBodyHtml = true;
                mail.Body = noidung;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.ReplyTo = new MailAddress(EmailName);
                //   mail.Bcc.Add(new MailAddress(EmailName));
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                return false;
                //     MessageBox.Show(ex.ToString());
                //  Response.Write("Khong  thể gửi thư " + ex.ToString());
            }
            return check;
        }

        public bool sendMailKhac(string email, string title, string noidung, int nguoinhap)
        {
            //   sendMai("hieulc1977@yahoo.com;cuongchiluong@yahoo.com", "MIS: Thêm khách hàng ", "<b>Tên khách hàng:  " + objCustomer.TenKhachHang + "</b><br/> <b>Địa chỉ:  " + objCustomer.DiaChi + "</b><br/> Điện thoại: " + objCustomer.SoDienThoai + "<br/> Email: " + objCustomer.TempStr2 + "<br/> Nội dung yêu cầu:<br/> " + objCustomer.TempStr3 + "<br/> Cán bộ nhập: " + getNguoitao(this.UserId.ToString()) + "<br/> Cán bộ Pre-Sale: " + getNguoitao(objCustomer.TempInt1.ToString()));
            CustomerController objDepartments = new CustomerController();
            Customer objCustomer = new Customer();
            DotNetNuke.Entities.Users.UserController objUserController = new DotNetNuke.Entities.Users.UserController();
            ArrayList listroles = objUserController.GetUsers(0, true, true);
            List<UserInfo> liUserInfo = new System.Collections.Generic.List<UserInfo>();
            List<UserInfo> liUserInfo1, liUserInfo2, liUserInfo3, liUserInfo4, liUserInfo5, liUserInfo6 = new List<UserInfo>();
            UserInfo temp = new DotNetNuke.Entities.Users.UserInfo();


            temp.UserID = 0;
            temp.DisplayName = "---------------";
            liUserInfo1 = new List<UserInfo>();
            liUserInfo2 = new List<UserInfo>();
            liUserInfo3 = new List<UserInfo>();
            liUserInfo4 = new List<UserInfo>();
            liUserInfo5 = new List<UserInfo>();
            foreach (DotNetNuke.Entities.Users.UserInfo obj2 in liUserInfo)
            {
                if (obj2.IsInRole("Pre-Sale"))
                {
                    liUserInfo2.Add(obj2);
                }
            }




            ContractTemplateLogController ctr = new ContractTemplateLogController();
            ContractTemplateLog obj = new ContractTemplateLog();
            DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserById(0, nguoinhap);
            //user.Email
            // danh sach cac ytu cau

            bool check = true;

            string[] mails = email.Split(';');
            string EmailName = "senwebthongbao@gmail.com";//ConfigurationSettings.AppSettings["EmailName"];
            string EmailPassword = "senwebthongbao123456";// ConfigurationSettings.AppSettings["EmailPassword"];
            string EmailHost = "smtp.gmail.com";// ConfigurationSettings.AppSettings["EmailHost"];
            string EmailPort = "587";// ConfigurationSettings.AppSettings["EmailPort"];
            string res = "";

            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new System.Net.NetworkCredential(EmailName, EmailPassword);
            SmtpServer.Port = int.Parse(EmailPort);
            SmtpServer.Host = EmailHost;
            SmtpServer.EnableSsl = true;
            MailMessage mail = new MailMessage();

            try
            {
                mail.From = new MailAddress(EmailName, "MIS Thông báo", System.Text.Encoding.UTF8);
                Byte i;

                //  mail.To.Add("nammct@gmail.com");
                if (user != null && user.Email.Length > 7)
                {
                    bool checkemail = true;

                    for (int ii = 0; ii < mails.Length; ii++)
                    {
                        if (mails[ii].Trim() == user.Email.Trim())
                        {
                            checkemail = false;
                        }
                    }
                    if (checkemail)
                        mail.To.Add(user.Email);
                }

                for (int ii = 0; ii < mails.Length; ii++)
                {
                    mail.To.Add(mails[ii]);
                }
                mail.Subject = title + objCustomer.TenKhachHang;
                //LinkedResource logo = new LinkedResource(path);
                //logo.ContentId = "companylogo";
                // AlternateView alternateView1 = AlternateView.CreateAlternateViewFromString(noidung, null, MediaTypeNames.Text.Html);
                //   alternateView1.LinkedResources.Add(logo);
                //mail.AlternateViews.Add(alternateView1);

                mail.IsBodyHtml = true;
                mail.Body = noidung;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.ReplyTo = new MailAddress(EmailName);
                //   mail.Bcc.Add(new MailAddress(EmailName));
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                return false;
                //     MessageBox.Show(ex.ToString());
                //  Response.Write("Khong  thể gửi thư " + ex.ToString());
            }
            return check;
        }
        public string getNguoitao(string id)
        {
            string res = "";
            // Response.Write("<br/>" + id);
            DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUserById(0, int.Parse(id));
            if (user != null)
                return user.DisplayName;
            return res;
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// adds an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objCustomer">The Customer object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddCustomer(Customer objCustomer)
        {
            // if (objCustomer.CustomerName.Trim() != "")
            {
                DataProvider.Instance().AddCustomer(objCustomer.ModuleId,
                    objCustomer.PlanInfoID,
objCustomer.TenKhachHang,
objCustomer.DiaChi,
objCustomer.SoDienThoai,
objCustomer.Fax,
objCustomer.MST,
objCustomer.STK,
objCustomer.NguoiPhuTrach,
objCustomer.Thongtinkhac,
objCustomer.InsertDate,
objCustomer.UpdateDate,
objCustomer.CreateByUser,
objCustomer.UpdateByUser,
objCustomer.IsDelete,
objCustomer.TempInt1,
objCustomer.TempInt2,
objCustomer.TempInt3,
objCustomer.TempInt4,
objCustomer.TempStr1,
objCustomer.TempStr2,
objCustomer.TempStr3,
objCustomer.TempStr4,
objCustomer.TempDate1,
objCustomer.TempDate2
                    );
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// deletes an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeleteCustomer(int ModuleId, int CustomerId)
        {
            DataProvider.Instance().DeleteCustomer(ModuleId, CustomerId);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public Customer GetCustomer(int ModuleId, int CustomerId)
        {
            return CBO.FillObject<Customer>(DataProvider.Instance().GetCustomer(ModuleId, CustomerId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public List<Customer> GetCustomers(int ModuleId)
        {
            return CBO.FillCollection<Customer>(DataProvider.Instance().GetCustomers(ModuleId));
        }

        public List<Customer> GetCustomersByCond(int ModuleId, string cond, string sql)
        {
            return CBO.FillCollection<Customer>(DataProvider.Instance().GetCustomersByCond(ModuleId, cond, sql));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// saves an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objCustomer">The Customer object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdateCustomer(Customer objCustomer)
        {
            // if (objCustomer.CustomerName.Trim() != "")
            {
                DataProvider.Instance().UpdateCustomer(objCustomer.ModuleId,
                    objCustomer.CustomerID,
objCustomer.PlanInfoID,
objCustomer.TenKhachHang,
objCustomer.DiaChi,
objCustomer.SoDienThoai,
objCustomer.Fax,
objCustomer.MST,
objCustomer.STK,
objCustomer.NguoiPhuTrach,
objCustomer.Thongtinkhac,
objCustomer.InsertDate,
objCustomer.UpdateDate,
objCustomer.CreateByUser,
objCustomer.UpdateByUser,
objCustomer.IsDelete,
objCustomer.TempInt1,
objCustomer.TempInt2,
objCustomer.TempInt3,
objCustomer.TempInt4,
objCustomer.TempStr1,
objCustomer.TempStr2,
objCustomer.TempStr3,
objCustomer.TempStr4,
objCustomer.TempDate1,
objCustomer.TempDate2

                    );
            }
        }
        // End kết hợp xử lý
        #endregion

        #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetSearchItems implements the ISearchable Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {
            SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
            List<Customer> colCustomers = GetCustomers(ModInfo.ModuleID);

            foreach (Customer objCustomer in colCustomers)
            {
                if (objCustomer != null)
                {
                    SearchItemInfo SearchItem = new SearchItemInfo();
                    SearchItemCollection.Add(SearchItem);
                }
            }

            return SearchItemCollection;
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be exported</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleID)
        {
            string strXML = "";
            List<Customer> colCustomers = GetCustomers(ModuleID);

            if (colCustomers.Count != 0)
            {
                strXML += "<Customers>";
                foreach (Customer objCustomer in colCustomers)
                {
                    strXML += "<Customer>";
                    strXML += "<content>" + XmlUtils.XMLEncode(objCustomer.TempStr1) + "</content>";
                    strXML += "</Customer>";
                }
                strXML += "</Customers>";
            }

            return strXML;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            XmlNode xmlCustomers = Globals.GetContent(Content, "Customers");

            foreach (XmlNode xmlCustomer in xmlCustomers.SelectNodes("Customer"))
            {
                Customer objCustomer = new Customer();

                objCustomer.ModuleId = ModuleID;
                //    objCustomer.CustomerName = xmlCustomer.SelectSingleNode("content").InnerText;
                //      objCustomer.CreatedByUser = UserId;
                AddCustomer(objCustomer);
            }

        }
        public bool checkRole(string id, string rolelist)
        {
            bool res = false;
            string[] list = rolelist.Split(';');
            DotNetNuke.Entities.Users.UserInfo USERINFO = DotNetNuke.Entities.Users.UserController.GetUserById(0, int.Parse(id));
            for (int i = 0; i < list.Length; i++)
                if (USERINFO.IsInRole(list[i]))
                {
                    return true;
                }
            return res;
        }
        public int getType(string id)
        {
            int res = 0;
            string rolelist = "bangiamdoc;phongbientap;phongcongnghe;phonghanhchinh;phongkehoach;phongketoan;phongkinhdoanh;phongphathanh;vanphong;truongphongbt";
            string[] list = rolelist.Split(';');
            DotNetNuke.Entities.Users.UserInfo USERINFO = DotNetNuke.Entities.Users.UserController.GetUserById(0, int.Parse(id));
            for (int i = 0; i < list.Length; i++)
                if (USERINFO.IsInRole(list[i]))
                {
                    return (i + 1);
                }
            return res;
        }

        public bool sendMai(string email, string title, string noidung)
        {
            // <add key="EmailName" value="sell.huyhoang@gmail.com" />
            //<add key="EmailPassword" value="huyhoang111111" />
            //<add key="EmailHost" value="smtp.gmail.com" />
            //  <add key="EmailPort" value="587" />
            bool check = true;
            string[] mails = email.Split(';');
            string EmailName = "senwebthongbao@gmail.com";//ConfigurationSettings.AppSettings["EmailName"];
            string EmailPassword = "senwebthongbao123456";// ConfigurationSettings.AppSettings["EmailPassword"];
            string EmailHost = "smtp.gmail.com";// ConfigurationSettings.AppSettings["EmailHost"];
            string EmailPort = "587";// ConfigurationSettings.AppSettings["EmailPort"];
            string res = "";
            SmtpClient SmtpServer = new SmtpClient();
            SmtpServer.Credentials = new System.Net.NetworkCredential(EmailName, EmailPassword);
            SmtpServer.Port = int.Parse(EmailPort);
            SmtpServer.Host = EmailHost;
            SmtpServer.EnableSsl = false;
            MailMessage mail = new MailMessage();
            //mail.BodyEncoding
            // string image = ImageFile.ImageUrl;
            // string path = "http://huyhoangbook.vn/" + image;
            try
            {
                mail.From = new MailAddress(EmailName, "TTNB Thông báo", System.Text.Encoding.UTF8);
                Byte i;

                mail.To.Add("nammct@gmail.com");
                for (int ii = 0; ii < mails.Length; ii++)
                {
                    mail.Bcc.Add(mails[ii]);
                }
                mail.Subject = title;
                //LinkedResource logo = new LinkedResource(path);
                //logo.ContentId = "companylogo";
                // AlternateView alternateView1 = AlternateView.CreateAlternateViewFromString(noidung, null, MediaTypeNames.Text.Html);
                //   alternateView1.LinkedResources.Add(logo);
                //mail.AlternateViews.Add(alternateView1);

                mail.IsBodyHtml = true;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mail.ReplyTo = new MailAddress(EmailName);
                //   mail.Bcc.Add(new MailAddress(EmailName));
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                return false;
                //     MessageBox.Show(ex.ToString());
                //   Response.Write("Khong  thể gửi thư " + ex.ToString());
            }
            return check;
        }

        #endregion

    }
}

